<template>
	<view class="outerView">
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="this.queryParam.status" :values="items" @clickItem=onClickItem
				styleType="text" />
		</view>
		<view class="content">
			<view v-if="this.queryParam.status === 0">
				<view class="viewList" v-for="(item,index) in list">
					<view class="viewL" v-if="item.coupon.type=='满减券'">
						<view class="money">￥{{item.coupon.preferentialMoney}}</view>
						<view class="rule">满{{item.coupon.triggerMoney}}元可用</view>
					</view>
					<view class="viewL" v-if="item.coupon.type=='折扣券'">
						<view class="money" style="padding: 0;">{{item.coupon.discount}}折</view>
					</view>

					<view class="line"></view>
					<view class="viewR">
						<view class="title" v-if="item.coupon.source==0">通用所有店铺均可使用</view>
						<view class="title" v-if="item.coupon.source==1">仅限{{item.shop.name}}使用</view>
						<view class="rBottom">
							<view class="date">{{item.expirationStart}}至{{item.expirationEnd}}</view>
							<button class="button" @click="getCoupons(item.id)">立即使用</button>
						</view>
					</view>
				</view>
			</view>
			<view v-if="this.queryParam.status === 1">
				<view class="viewList" v-for="(item,index) in list">
					<view class="viewLEnd" v-if="item.coupon.type=='满减券'">
						<view class="money">￥{{item.coupon.preferentialMoney}}</view>
						<view class="rule">满{{item.coupon.triggerMoney}}元可用</view>
					</view>
					<view class="viewLEnd" v-if="item.coupon.type=='折扣券'">
						<view class="money" style="padding: 0;">{{item.coupon.discount}}折</view>
					</view>
					<view class="line"></view>
					<view class="viewR">
						<view class="title" v-if="item.coupon.source==0">通用所有店铺均可使用</view>
						<view class="title" v-if="item.coupon.source==1">仅限{{item.shop.name}}使用</view>
						<view class="rBottom">
							<view class="date">{{item.expirationStart}}至{{item.expirationEnd}}</view>
							<button class="buttonEnd" @click="getCoupons(item.id)">已使用</button>
						</view>
					</view>
				</view>
			</view>
			<view v-if="this.queryParam.status === 2">
				<view class="viewList" v-for="(item,index) in list">
					<view class="viewLEnd" v-if="item.coupon.type=='满减券'">
						<view class="money">￥{{item.coupon.preferentialMoney}}</view>
						<view class="rule">满{{item.coupon.triggerMoney}}元可用</view>
					</view>
					<view class="viewLEnd" v-if="item.coupon.type=='折扣券'">
						<view class="money" style="padding: 0;">{{item.coupon.discount}}折</view>
					</view>
					<view class="line"></view>
					<view class="viewR">
						<view class="title" v-if="item.coupon.source==0">通用所有店铺均可使用</view>
						<view class="title" v-if="item.coupon.source==1">仅限{{item.shop.name}}使用</view>
						<view class="rBottom">
							<view class="date">{{item.expirationStart}}至{{item.expirationEnd}}</view>
							<button class="buttonEnd" @click="getCoupons(item.id)">已过期</button>
						</view>
					</view>
				</view>
			</view>
			<view v-if="list.length==0" style="padding-top: 200rpx;font-size: 34rpx; text-align: center;">
				暂无更多
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['未使用', '已使用', '已过期'],
				queryParam: {
					status: 0,
					nowTimeLeEndTime: null,
					nowTimeGtEndTime: null
				},
				list: [],
				total: 0,
				requestFlag: false,
			}
		},
		methods: {
			onClickItem(e) {
				if (this.queryParam.status !== e.currentIndex) {
					this.queryParam.status = e.currentIndex
				}
				if (this.queryParam.status == 0) {
					this.queryParam.nowTimeLeEndTime = new Date();
					this.queryParam.nowTimeGtEndTime = null;
				} else if (this.queryParam.status == 2) {
					this.queryParam.nowTimeLeEndTime = null;
					this.queryParam.nowTimeGtEndTime = new Date();
				} else {
					this.queryParam.nowTimeLeEndTime = null;
					this.queryParam.nowTimeGtEndTime = null;
				}
				this.list = [];
				this.getList();
			},
			//获取优惠券
			getList() {
				this.requestFlag = true;
				uni.request({
					url: 'http://localhost:7000/business/coupon/listBy',
					data: this.queryParam,
					method: 'GET',
					header: {
						authorization: getApp().globalData.token
					},
					success: (resp) => {
						if (resp.data.code == 200) {
							console.log(resp);
							this.list = [...this.list, ...resp.data.data];
							this.total = resp.data.total;
							// this.requestFlag = false;
							// console.log(resp.data.rows);
						} else {
							uni.showToast({
								title: '没有更多数据了',
								icon: 'none'
							})
						}
					},
					fail: (resp) => {}
				})
			},
		},
		onLoad() {

		},
		onShow() {
			this.list = [];
			this.getList()
		},
		onReachBottom() {}
	}
</script>

<style lang="scss">
	// 导航栏样式
	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 0;
	}

	.uni-common-mt {
		// margin-top: 30px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		// padding: 0px 30px;
	}

	//内容样式

	.outerView {
		height: 100%;
		background-color: #fff;
	}

	.viewList {
		display: flex;
		align-items: center;
		background-color: #F8F8F8;
		margin: 10rpx 5rpx;
		border-radius: 10px;
	}

	.viewL {
		left: 14px;
		top: 88px;
		width: 115px;
		height: 94px;
		line-height: 39px;
		border-radius: 10px;
		background-color: rgba(29, 111, 255, 1);
		color: rgba(255, 255, 255, 1);
		font-size: 28px;
		text-align: center;
		font-family: Roboto;
		border: 1px solid rgba(187, 187, 187, 1);

		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		align-content: center;
		margin: 30rpx;
	}

	.money {
		// padding-top: 30rpx;
	}

	.rule {
		left: 33px;
		top: 155px;
		width: 76px;
		height: 19px;
		line-height: 19px;
		// color: rgba(255, 255, 255, 1);
		font-size: 13px;
		text-align: left;
		font-family: PingFangSC-regular;
		padding-bottom: 30rpx;
	}

	.line {
		width: 1rpx;
		height: 150rpx;
		background-color: #999;
	}

	.viewR {
		width: 480rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		align-content: center;
	}

	.title {
		left: 153px;
		top: 106px;
		width: 154px;
		height: 19px;
		line-height: 19px;
		color: rgba(68, 68, 68, 1);
		font-size: 13px;
		text-align: left;
		font-family: PingFangSC-regular;
		padding-bottom: 30rpx;
	}

	.rBottom {
		display: flex;
		height: 16px;
	}

	.date {
		left: 153px;
		top: 155px;
		width: 145px;
		height: 26px;
		line-height: 26px;
		color: rgba(234, 23, 3, 1);
		font-size: 11px;
		text-align: left;
		font-family: PingFangSC-regular;
	}

	.button {
		width: 65px;
		height: 26px;
		line-height: 26px;
		border-radius: 4px;
		background-color: rgba(0, 132, 255, 1);
		color: rgba(255, 255, 255, 1);
		font-size: 14px;
		text-align: center;
		font-family: Roboto;
	}

	//已使用和已过期样式，将颜色改为灰色
	.viewLEnd {
		left: 14px;
		top: 88px;
		width: 115px;
		height: 94px;
		line-height: 39px;
		border-radius: 10px;
		background-color: #F4F4F4;
		color: #000000;
		font-size: 28px;
		text-align: center;
		font-family: Roboto;
		border: 1px solid rgba(187, 187, 187, 1);

		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		align-content: center;
		margin: 30rpx;
	}

	.dateEnd {
		left: 153px;
		top: 155px;
		width: 145px;
		height: 26px;
		line-height: 26px;
		color: #B5B4B5;
		font-size: 11px;
		text-align: left;
		font-family: PingFangSC-regular;
	}

	.buttonEnd {
		width: 65px;
		height: 26px;
		line-height: 26px;
		border-radius: 4px;
		background-color: #BEBEBE;
		color: rgba(255, 255, 255, 1);
		font-size: 14px;
		text-align: center;
		font-family: Roboto;
	}
</style>

<style scoped>
	/deep/uni-button {
		padding-left: 0px;
		padding-right: 0px;
	}
</style>